var share = share || {};

//此插件依赖QQ分享sdk，请保证在引入此插件前引入:<script src="http://qzonestyle.gtimg.cn/qzone/app/qzlike/qzopensl.js#jsdate=20111201" charset="utf-8"></script>
//为Share组件添加一些分享的方法
(function(){
	
	//element:用来放置分享按钮的容器节点(DOM对象);data:具体的一些分享信息;
	share.shareQzone = function(element, data){
		var renderData = renderQzoneData(data);
		console.log(renderData);
		element.innerHTML = ['<a version="1.0" class="qzOpenerDiv" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?',renderData.join('&'),'" target="_blank">分享</a>'].join('');
	};

	share.shareQzoneFriend = function(element, data){
		var renderData = renderQzoneFriendData(data);
		element.innerHTML = ['<a href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?',renderData.join('&'),'" target="_blank" title="分享到腾讯朋友"><img src="http://imgcache.qq.com/qzone_v6/proj_connect_open/img/share/share_py.png" alt="分享到腾讯朋友" border="0" /></a>'].join('');
	};


	function renderQzoneData(data){
		var pdata = {
				url: data.url || location.href,
				showcount: data.showcount?'1':'0',/*是否显示分享总数,显示：'1'，不显示：'0' */
				desc: data.describe || '',/*默认分享理由(可选)*/
				summary: data.summary || '',/*分享摘要(可选)*/
				title: data.title || '',/*分享标题(可选)*/
				site: data.site || '',/*分享来源 如：腾讯网(可选)*/
				pics: data.pics || '', /*分享图片的路径(可选)*/
				style: '101',
				width: 199,
				height: 30
			};
			var s = [];
			for(var i in pdata){
				s.push(i + '=' + encodeURIComponent(pdata[i]||''));
			}
		return s;
	}

	function renderQzoneFriendData(data){
		var pdata = {
				url: data.url || location.href,/*分享指向的链接，默认值就当前页面*/
				to: 'pengyou',/*分享到QQ朋友网固定值*/
				desc: data.describe || '',/*默认分享理由(可选)*/
				summary: data.summary || '',/*分享摘要(可选)*/
				title: data.title || '',/*分享标题(可选)*/
				site: data.site || '',/*分享来源 如：腾讯网(可选)*/
				pics: data.pics || '', /*分享图片的路径(可选)*/
			};
			var s = [];
			for(var i in pdata){
				s.push(i + '=' + encodeURIComponent(pdata[i]||''));
			}
		return s;
	}
	
})();